home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / freemacs.arc / EMACS.ASM < prev    next >
Assembly Source File  |  1988-03-17  |  27KB  |  1,428 lines

  1. ;History:243,45
  2. test_prims    equ    0
  3.     page    ,132
  4.  
  5.     .xlist
  6.     include    memory.def
  7.     include    mintdefs.asm
  8.     include    /include/findfile.inc
  9.  
  10. data    segment    byte public
  11.  
  12. ;the following externs are defined in 'mintprim'
  13.     extrn    phd_seg: word
  14.     extrn    read_errors: word
  15.     extrn    write_errors: word
  16.  
  17. ;the following externs are defined in 'mintscan'
  18.     extrn    actptr: word
  19.     extrn    fbgn: word, fend: word
  20.     extrn    next_ids: word
  21.  
  22. ;the following externs are defined in 'mintform'
  23.     extrn    formhash: word
  24.     extrn    syntax_table: word
  25.  
  26. ;the following externs are defined in the computer-dependent file.
  27.     extrn    max_screen_line: byte
  28.  
  29.     public    filename
  30. filename    db    64 dup(?)
  31. filename2    db    64 dup(?)
  32.  
  33. rename_error    db    'Rename error'
  34. rename_error_len    equ    $-rename_error
  35.  
  36.     extrn    breakchar: word
  37.  
  38.     extrn    next_redisp_line: word
  39.  
  40. initial_ids    label    byte
  41. db '#(rd)#(ow,(',13,10
  42. db 'EMACS, a programmable editor - Version 1.03',13,10
  43. db 'Copyright (C) Russell Nelson 1986, 1987',13,10
  44. db '))'
  45. db '#(ev)'
  46. db '#(an,Loading #(env.EMACS)emacs.ed...)'
  47. db '#(==,#(ll,#(env.EMACS)emacs.ed#(es,#(ls,(,)))),,('
  48. db '    #(an,Starting editor...)'
  49. db '    #(##(lib-name)&setup)'
  50. db '),('
  51. db '    #(ow,Cannot find '
  52. db '        #(ev)'
  53. db '        #(env.EMACS)emacs.ed - halting)'
  54. db '    #(hl,1)'
  55. db '))'
  56. db 0
  57.  
  58.     public    standard_ids
  59. standard_ids    db    '#(d,#(g))',0
  60.  
  61. nokbd_ids    db    '#(k)#(d,#(g))',0
  62.  
  63. byte_ptr    label    byte
  64.  
  65. foreback_color    label    word
  66. fore_color    db    7
  67. back_color    db    0
  68.  
  69.  
  70. variable_table    label    byte
  71.     db    'eFBpousfwnrctbml'
  72. variable_count    equ    $-variable_table
  73.  
  74. lv_prim_table    label    word
  75.     dw    lv_prim_e
  76.     dw    lv_prim_Fore
  77.     dw    lv_prim_Back
  78.     dw    lv_prim_p
  79.     dw    lv_prim_o
  80.     dw    lv_prim_u
  81.     dw    lv_prim_s
  82.     dw    lv_prim_f
  83.     dw    lv_prim_w
  84.     dw    lv_prim_n
  85.     dw    lv_prim_r
  86.     dw    lv_prim_c
  87.     dw    lv_prim_t
  88.     dw    lv_prim_b
  89.     dw    lv_prim_m
  90.     dw    lv_prim_l
  91.  
  92. sv_prim_table    label    word
  93.     dw    sv_prim_e
  94.     dw    sv_prim_Fore
  95.     dw    sv_prim_Back
  96.     dw    sv_prim_p
  97.     dw    sv_prim_o
  98.     dw    sv_prim_u
  99.     dw    sv_prim_s
  100.     dw    sv_prim_f
  101.     dw    sv_prim_w
  102.     dw    sv_prim_n
  103.     dw    sv_prim_r
  104.     dw    sv_prim_c
  105.     dw    sv_prim_t
  106.     dw    sv_prim_b
  107.     dw    sv_prim_m
  108.     dw    sv_prim_l
  109.  
  110.     extrn    stackp: byte
  111.  
  112.  
  113. data    ends
  114.  
  115.  
  116. code    segment    byte public
  117.     assume    cs:code, ds:data, es:data
  118.  
  119.     extrn    init_memory: near
  120.  
  121.     extrn    set_screen_color: near
  122.  
  123.     extrn    redisplay: near        ;ax=line to leave the cursor on.
  124.  
  125.     extrn    read_firstline: near
  126.     extrn    read_lastline: near
  127.     extrn    read_newrow: near
  128.     extrn    read_linesbefore: near
  129.     extrn    read_linecount: near
  130.     extrn    read_buffer_modified: near
  131.     extrn    store_buffer_modified: near
  132.  
  133.     extrn    read_showblanks: near
  134.     extrn    store_showblanks: near
  135.  
  136.     extrn    read_top_percent: near
  137.     extrn    read_bot_percent: near
  138.     extrn    store_top_percent: near
  139.     extrn    store_bot_percent: near
  140.  
  141.     extrn    read_panes: near
  142.     extrn    read_other_window: near
  143.     extrn    read_current_window: near
  144.     extrn    store_panes: near
  145.     extrn    store_other_window: near
  146.     extrn    store_current_window: near
  147.  
  148.     extrn    chrout: near        ;al=char to overwrite to screen.
  149.  
  150.     extrn    paint_screen: near    ;sets entire screen to be repainted.
  151.  
  152.     extrn    paint_window: near    ;causes the current buffer to be shown in the current window.
  153.  
  154.     extrn    insert_string: near    ;si,cx describe the string.
  155.  
  156.     extrn    buffer_allocate: near    ;entry: cx=buffer number to select,
  157.                     ;  cx=0 to create new buffer.
  158.                     ;  ax=0 for read/write buffer.
  159.                     ;exit: ax=new buffer number if enough
  160.                     ;  memory, ax=0 otherwise.
  161.     extrn    read_mark: near        ;entry: al=mark to read to.
  162.                     ;exit: es:si, cx describing string.
  163.  
  164.     extrn    del_to_mark: near    ;entry: al=mark to delete to.
  165.  
  166.     extrn    set_mark: near        ;entry: al=dest mark, ah=source mark.
  167.  
  168.     extrn    goto_mark: near        ;entry: al-mark to go to.
  169.  
  170.     extrn    stack_marks: near    ;entry: ax>0 to create temp marks,
  171.                     ;  ax=0 to delete temp marks,
  172.                     ;  ax<0 to create perm marks and delete
  173.                     ;  all temp marks.
  174.  
  175.     extrn    compute_cursor: near    ;exit with dx=column (0..65535)
  176.  
  177.     extrn    set_column: near    ;entry: ax=desired column
  178.  
  179.     extrn    set_line: near        ;entry: ax=desired line.
  180.  
  181.     extrn    ring_the_bell: near
  182.  
  183.  
  184. ;the following extrns are in the computer-dependent file
  185.     extrn    xychrout: near
  186.     extrn    clear_count: near
  187.     extrn    position_cursor: near
  188.     extrn    check_for_key: near
  189.     public    xyputch
  190. xyputch:
  191.     jmp    xychrout
  192.  
  193.  
  194. ;the following extrns are in 'files'
  195.     extrn    read_file: near
  196.     extrn    write_file: near
  197.  
  198. ;the following extrns are in 'search'
  199.     extrn    regexp_pat: near
  200.     extrn    literal_pattern: near
  201.     extrn    search: near
  202.  
  203. ;the following extrns are in 'mintscan'
  204.     extrn    nomem: near
  205.  
  206. ;the following externs are in 'pick'
  207.     extrn    pick_on: near
  208.     extrn    pick_off: near
  209.     extrn    check_pick: near
  210.     extrn    get_pick_values: near
  211.  
  212.     public    mint_init
  213. mint_init:
  214. ;enter with ax=first free paragraph, bx=first paragraph after end of memory.
  215. ;exit with same results as init_memory returns.
  216.     call    init_memory
  217.     mov    next_ids,offset initial_ids
  218.     ret
  219.  
  220.     public    init_ids
  221. init_ids:
  222.     mov    sp,offset stackp
  223.     call    check_for_key        ;use the standard ids only if kbd ready.
  224.     jnz    init_ids_1
  225.     cmp    next_ids,offset standard_ids
  226.     jne    init_ids_1
  227.     mov    next_ids,offset nokbd_ids
  228. init_ids_1:
  229.     jmp    init_ids_continue
  230.  
  231.     extrn    init_ids_continue: near
  232.  
  233.  
  234. ;this routine should check for a break character.  If it gets one, it
  235. ;  gets rid of its return address and jump to init_ids.  Also, no registers
  236. ;  should be changed.
  237.     public    check_breakchar
  238. check_breakchar:
  239.     push    ax
  240.     call    check_for_key
  241.     jz    check_breakchar_1
  242.   if 1
  243.     cmp    ax,7            ;^G?
  244.   else
  245.     cmp    ax,breakchar
  246.   endif
  247.     jne    check_breakchar_1
  248.     call    get_key_value
  249.     add    sp,4            ;get rid of the return address and ax.
  250.     jmp    init_ids
  251. check_breakchar_1:
  252.     pop    ax
  253.     ret
  254.  
  255.  
  256.     if    test_prims
  257.  
  258. ;test primitive.  fills memory to the max.  strictly for testing only.
  259. ts_prim:
  260.     di_points_fbgn
  261.     mov    cx,actptr
  262.     sub    cx,di
  263.     dec    cx
  264.     push    cx
  265.     mov    al,' '
  266.     rep    stosb
  267.     pop    cx
  268.     jmp    return_sicx
  269.  
  270.  
  271. ;dump formhash.  strictly for testing only.
  272. tt_prim:
  273.     mov    cx,256
  274.     di_points_fbgn
  275.     chk_actptr_cnt
  276.     mov    si,offset formhash
  277. tt_prim_1:
  278.     test    cx,3fh
  279.     jne    tt_prim_4
  280.     mov    ax,LINENEW
  281.     stosw
  282. tt_prim_4:
  283.     mov    dx,0
  284.     lodsw
  285.     mov    bx,ax
  286. tt_prim_2:
  287.     cmp    bx,NIL        ;at end of list yet?
  288.     je    tt_prim_3
  289.     mov    bx,[bx].hash_link
  290.     inc    dx
  291.     jmp    tt_prim_2
  292. tt_prim_3:
  293.     mov    ax,dx        ;get the count
  294.     add    al,'0'        ;convert to ascii (cheaply)
  295.     stosb
  296.     loop    tt_prim_1
  297.     jmp    return_tos
  298.  
  299.     endif
  300.  
  301. ;redisplay.
  302. rd_prim:
  303.     call    getarg1
  304.     jcxz    rd_prim_1
  305.     call    paint_screen        ;paint,
  306.     call    paint_window
  307.     jmp    short rd_prim_3        ; always redisplay
  308. rd_prim_1:
  309.     call    check_for_key        ;redisplay only if no key waiting.
  310.     jnz    rd_prim_2
  311. rd_prim_3:
  312.     call    redisplay
  313. rd_prim_2:
  314.     jmp    return_null
  315.  
  316.  
  317. st_prim:
  318. ;set the syntax table.
  319.     call    find_arg1
  320.     jc    st_prim_1
  321.     mov    bx,NIL            ;if form not found, use NIL.
  322. st_prim_1:
  323.     mov    syntax_table,bx        ;remember where the syntax table is.
  324.     jmp    return_null
  325.  
  326.  
  327.  
  328. ;overwrite the screen.
  329. ow_prim:
  330.     call    getarg1
  331.     jcxz    ow_prim_2
  332. ow_prim_1:
  333.     lodsb
  334.     xor    ah,ah
  335.     call    chrout
  336.     push    si
  337.     push    cx
  338.     pop    cx
  339.     pop    si
  340.     loop    ow_prim_1
  341. ow_prim_2:
  342.     jmp    return_null
  343.  
  344.  
  345.     extrn    get_math: near
  346.     extrn    gotoxy: near
  347.  
  348. ;gotoxy
  349. xy_prim:
  350.     call    get_math
  351.     mov    dh,al
  352.     mov    dl,bl
  353.     call    gotoxy
  354.     jmp    return_null
  355.  
  356.  
  357. ;announce a string
  358. an_prim:
  359.     mov    bx,80            ;end of the line.
  360.     mov    dl,max_screen_line    ;get the row.
  361.     inc    dl
  362.     mov    cx,2            ;if the second arg is non-null,
  363.     call    getarg
  364.     jcxz    an_prim_1
  365.     call    read_lastline        ;  put the announcement after the current window.
  366.     mov    dl,al
  367. an_prim_1:
  368.     inc    dl            ;put our announcement after it.
  369.     mov    dh,0            ;start in this column
  370.  
  371.     push    cx            ;remember if arg2 is null or not.
  372.  
  373.     call    getarg1
  374.     jcxz    an_prim_2        ;if null, we're done.
  375.     cmp    cx,bx            ;more than we can print?
  376.     jb    an_prim_3        ;no.
  377.     mov    cx,bx            ;yes - print only as many as will fit.
  378. an_prim_3:
  379.     lodsb
  380.     mov    ah,0
  381.     call    xychrout
  382.     inc    dh
  383.     loop    an_prim_3
  384. an_prim_2:
  385.  
  386.     pop    cx            ;pop the size of arg2.
  387.     or    cx,cx
  388.     jne    an_prim_4        ;if it's null,
  389.     call    position_cursor        ;  put the cursor at the end of the string
  390. an_prim_4:
  391.     call    clear_count        ;clear to the end of the annunciator.
  392.     jmp    return_null
  393.  
  394.  
  395. ;insert a string.
  396. is_prim:
  397.     call    getarg1
  398.     call    insert_string
  399.     jc    is_prim_1        ;go if we can't insert it.
  400.     jmp    return_null
  401. is_prim_1:
  402.     mov    cx,2
  403.     jmp    return_arg
  404.  
  405.  
  406. lv_prim:
  407. ;load variable
  408.     mov    bx,offset lv_prim_table
  409.     call    parse_variable
  410.     call    word ptr [bx]
  411.     di_points_fbgn
  412.     jmp    return_number
  413.  
  414. lv_prim_e:
  415.     mov    ax,actptr
  416.     sub    ax,fend
  417.     ret
  418.  
  419. lv_prim_Fore:
  420.     mov    ah,0
  421.     mov    al,fore_color
  422.     ret
  423.  
  424. lv_prim_Back:
  425.     mov    ah,0
  426.     mov    al,back_color
  427.     ret
  428.  
  429. lv_prim_p:
  430.     call    read_panes
  431.     mov    ah,0
  432.     ret
  433.  
  434. lv_prim_o:
  435.     call    read_other_window
  436.     ret
  437.  
  438. lv_prim_u:
  439.     call    read_current_window
  440.     ret
  441.  
  442. lv_prim_s:
  443.     call    read_top_percent
  444.     mov    ah,0
  445.     ret
  446. lv_prim_f:
  447.     call    read_bot_percent
  448.     mov    ah,0
  449.     ret
  450. lv_prim_w:
  451.     call    read_showblanks
  452.     inc    ax
  453.     ret
  454. lv_prim_n:
  455.     call    read_linecount
  456.     inc    ax
  457.     ret
  458. lv_prim_r:
  459.     call    read_newrow
  460.     inc    ax
  461.     ret
  462. lv_prim_c:
  463.     call    compute_cursor
  464.     mov    ax,dx
  465.     inc    ax
  466.     ret
  467. lv_prim_t:
  468.     call    read_firstline
  469.     mov    ah,0
  470.     inc    ax
  471.     ret
  472. lv_prim_b:
  473.     call    read_lastline
  474.     mov    ah,0
  475.     inc    ax
  476.     ret
  477. lv_prim_m:
  478.     call    read_buffer_modified
  479.     mov    ah,0
  480.     ret
  481. lv_prim_l:
  482.     call    read_linesbefore
  483.     inc    ax
  484.     ret
  485.  
  486.  
  487. sv_prim:
  488. ;store variable
  489.     mov    bx,offset sv_prim_table
  490.     call    parse_variable
  491.     mov    cx,2
  492.     call    getarg
  493.     push    bx
  494.     call    get_decimal
  495.     pop    bx
  496.     call    word ptr [bx]
  497.     jmp    return_null
  498.  
  499. sv_prim_Fore:
  500.     mov    fore_color,al
  501.     mov    ax,foreback_color
  502.     call    set_screen_color
  503.     ret
  504.  
  505. sv_prim_Back:
  506.     mov    back_color,al
  507.     mov    ax,foreback_color
  508.     call    set_screen_color
  509.     ret
  510.  
  511.  
  512. sv_prim_p:
  513.     call    store_panes
  514.     ret
  515.  
  516. sv_prim_o:
  517.     call    store_other_window
  518.     ret
  519.  
  520. sv_prim_u:
  521.     call    store_current_window
  522.     ret
  523.  
  524. sv_prim_s:
  525.     call    store_top_percent
  526.     ret
  527. sv_prim_f:
  528.     call    store_bot_percent
  529.     ret
  530. sv_prim_w:
  531.     call    store_showblanks    ;whitespace.
  532.     ret
  533. sv_prim_e:
  534. sv_prim_n:
  535. sv_prim_t:
  536. sv_prim_b:
  537.     ret
  538. sv_prim_r:
  539.     mov    next_redisp_line,ax
  540.     ret
  541. sv_prim_c:
  542.     call    set_column
  543.     ret
  544. sv_prim_m:
  545.     call    store_buffer_modified
  546.     ret
  547. sv_prim_l:
  548.     call    set_line
  549.     ret
  550.  
  551.  
  552.  
  553.  
  554. parse_variable:
  555. ;parse a variable letter.
  556. ;return bx -> proper entry in the table pointed to by bx on entry.
  557. ;the default is at the end of the table.
  558.     call    getarg1
  559.     mov    al,0        ;defaults to line
  560.     jcxz    parse_variable_1
  561.     lodsb
  562. parse_variable_1:
  563.     mov    di,offset variable_table
  564.     mov    cx,variable_count
  565.     repne    scasb
  566.     sub    cx,variable_count-1
  567.     neg    cx
  568.     shl    cx,1
  569.     add    bx,cx
  570.     ret
  571.  
  572.  
  573. pp_prim:
  574.     di_points_fbgn
  575.     mov    cx,11            ;make sure there's enough room.
  576.     chk_actptr_cnt
  577.     call    get_pick_values
  578.     push    dx            ;save vertical
  579.     mov    ax,cx
  580.     mov    cx,0
  581.     mov    bx,10
  582.     call    put_number
  583.     mov    al,','
  584.     stosb
  585.     pop    ax            ;pushed as dx
  586.     jmp    return_number
  587.  
  588.  
  589. sa_prim:
  590.     mov    bx,fend            ;make bx point to some free memory.
  591.     add    bx,2
  592.     mov    si,fbgn            ;point si at "sa".
  593.     mov    si,[si]            ;point si at the first arg.
  594.     mov    dx,0            ;count the arguments here.
  595. sa_prim_1:
  596.     cmp    si,[si]            ;are we pointing at fend?
  597.     je    sa_prim_2
  598.     mov    [bx],si            ;save a pointer to the argument.
  599.     add    bx,2
  600.     cmp    bx,actptr        ;enough room for the pointer?
  601.     jb    $+5
  602.     jmp    nomem
  603.     mov    si,[si]            ;make it point to next arg.
  604.     inc    dx
  605.     jmp    sa_prim_1
  606. sa_prim_2:
  607.     mov    cx,dx            ;prepare to compare again.
  608.     jcxz    sa_prim_4        ;no arguments - we're done.
  609.     dec    cx            ;we look at n-1 arguments.
  610.     jcxz    sa_prim_4        ;no arguments - we're done.
  611.     mov    bx,fend            ;make bx point to some free memory.
  612.     add    bx,2
  613.     mov    bp,0            ;keep a "swapped" flag here.
  614. sa_prim_3:
  615.     push    cx
  616.  
  617.     mov    si,[bx]            ;get the two arguments under consideration.
  618.     mov    di,[bx+2]
  619.  
  620.     mov    ax,[si]            ;compute length of this arg.
  621.     sub    ax,si
  622.     sub    ax,mark_overhead
  623.     add    si,mark_overhead-1    ;make si=> text of argument.
  624.  
  625.     mov    cx,[di]            ;compute length of this arg.
  626.     sub    cx,di
  627.     sub    cx,mark_overhead
  628.     add    di,mark_overhead-1    ;make si=> text of argument.
  629.  
  630.     cmp    ax,cx            ;if the first string is shorter,
  631.     jb    sa_prim_8        ;  return if if they're equal.
  632.  
  633.                     ;second string is smaller.
  634.     push    cx
  635.     repe    cmpsb            ;compare the two strings
  636.     pop    cx
  637.     jb    sa_prim_5        ;go if they're in order already.
  638.     ja    sa_prim_6        ;if they're not in order, swap them.
  639.     cmp    ax,cx            ;were the strings equal?
  640.     je    sa_prim_5        ;yes - don't swap them.
  641.     jmp    short sa_prim_6
  642.  
  643. sa_prim_8:
  644.     xchg    cx,ax            ;first string is smaller.
  645.     repe    cmpsb            ;compare the two strings
  646.     jbe    sa_prim_5        ;go if they're in order already.
  647.  
  648. sa_prim_6:
  649.     mov    ax,[bx]            ;swap them.
  650.     xchg    ax,[bx+2]
  651.     mov    [bx],ax
  652.     inc    bp            ;remember that we found one out of order.
  653. sa_prim_5:
  654.     pop    cx
  655.     add    bx,2
  656.     loop    sa_prim_3
  657.  
  658.     or    bp,bp            ;did we swap any?
  659.     jne    sa_prim_2        ;yes - not done sorting.
  660.  
  661. sa_prim_4:
  662.     mov    bx,fend            ;make bx point to some free memory.
  663.     add    bx,2
  664.     mov    di,bx            ;compute the end of the table.
  665.     add    di,dx
  666.     add    di,dx
  667.     push    di
  668. sa_prim_7:
  669.     mov    si,[bx]
  670.     add    bx,2
  671.     mov    cx,[si]            ;compute length of this arg.
  672.     sub    cx,si
  673.     sub    cx,mark_overhead
  674.     add    si,mark_overhead-1    ;make si=> text of argument.
  675.     inc    cx            ;include space for the comma.
  676.     chk_actptr_cnt
  677.     dec    cx
  678.     rep    movsb
  679.     mov    al,','            ;comma seperate the strings.
  680.     stosb
  681.  
  682.     dec    dx            ;done with all of them?
  683.     jne    sa_prim_7        ;no - do another.
  684.  
  685.     jmp    return_tos
  686.  
  687.  
  688. bl_prim:
  689.     call    ring_the_bell
  690.     jmp    return_null
  691.  
  692.  
  693. ;push/pop marks
  694. pm_prim:
  695.     call    getarg1
  696.     call    get_decimal
  697.     call    stack_marks
  698.     jc    pm_prim_1
  699.     jmp    return_null
  700. pm_prim_1:
  701.     mov    cx,2
  702.     jmp    return_arg_active
  703.  
  704.  
  705. ;set mark (to point)
  706. sm_prim:
  707.     mov    cx,2
  708.     call    getarg_mark
  709.     mov    al,'.'        ;if 2nd is missing, use '.'
  710.     jcxz    sm_prim_1
  711.     lodsb
  712. sm_prim_1:
  713.     mov    ah,al        ;get source mark
  714.     push    ax        ;save source mark
  715.     call    getarg_mark1
  716.     pop    bx        ;pushed as ax
  717.     mov    ah,bl        ;get dest mark
  718.     call    set_mark
  719.     jmp    return_null
  720.  
  721.  
  722. ;set point (to marks)
  723. sp_prim:
  724.     mov    cx,1
  725.     call    getarg
  726.     jcxz    sp_prim_1
  727. sp_prim_2:
  728.     lodsb
  729.     push    si
  730.     push    cx
  731.     call    goto_mark
  732.     pop    cx
  733.     pop    si
  734.     loop    sp_prim_2
  735. sp_prim_1:
  736.     jmp    return_null
  737.  
  738.  
  739. ;delete to mark
  740. dm_prim:
  741.     call    getarg_mark1
  742.     call    del_to_mark
  743.     jmp    return_null
  744.  
  745.  
  746. ;read to mark
  747. rm_prim:
  748.     call    getarg_mark1    ;get mark number to read from.
  749.     call    read_mark    ;returns es:si, cx describing string.
  750.     assume    ds:nothing
  751. ;    di_points_fbgn
  752.     mov    di,fbgn
  753.     dec    di
  754.     push    di
  755. ;    check_actptr_count
  756.     push    di
  757.     add    di,cx
  758.     jc    rm_prim_1    ;if overflow, there must be no room.
  759.     cmp    di,actptr    ;if collision with actptr, . .
  760.     jae    rm_prim_1
  761.     pop    di
  762.     rep    movsb        ;move the string.
  763.     push    es        ;restore our ds.
  764.     pop    ds
  765.     jmp    return_tos
  766. rm_prim_1:
  767.     add    sp,4        ;conserve the stack.
  768.     push    es        ;restore our ds.
  769.     pop    ds
  770.     mov    cx,2
  771.     jmp    return_arg_active
  772.     assume    ds:data
  773.  
  774.  
  775. ;count to mark
  776. rc_prim:
  777.     call    getarg_mark1    ;get mark number to read from.
  778.     call    read_mark    ;returns ds:si, cx describing string.
  779.     push    es        ;restore our ds.
  780.     pop    ds
  781.     mov    ax,cx
  782.     di_points_fbgn
  783.     jmp    return_number
  784.  
  785.  
  786. ;mark before point #(mb,mark,before,after)
  787. mb_prim:
  788.     call    getarg_mark1
  789.     call    read_mark
  790.     push    es        ;restore our ds.
  791.     pop    ds
  792.     jc    mb_prim_1    ;go if point is before mark
  793.     mov    cx,2
  794.     jmp    return_arg
  795. mb_prim_1:
  796.     mov    cx,3
  797.     jmp    return_arg
  798.  
  799.  
  800.  
  801. ;look pattern.  return arg 2 if bad pattern.
  802. lp_prim:
  803.     call    getarg1
  804.     call    literal_pattern
  805.     jc    lp_prim_1
  806.     jmp    return_null
  807. lp_prim_1:
  808.     mov    cx,2
  809.     jmp    return_arg_active
  810.  
  811.  
  812. ;look regular.  return arg 2 if bad pattern.
  813. lr_prim:
  814.     call    getarg1
  815.     call    regexp_pat
  816.     jc    lr_prim_1
  817.     jmp    return_null
  818. lr_prim_1:
  819.     mov    cx,2
  820.     jmp    return_arg_active
  821.  
  822.  
  823. ;look for a string.  return arg 1 if not found.
  824. lk_prim:
  825.     call    getarg_mark1
  826.     push    ax
  827.     mov    cx,2
  828.     call    getarg_mark
  829.     push    ax
  830.     mov    cx,3
  831.     call    getarg_mark
  832.     push    ax
  833.     mov    cx,4
  834.     call    getarg_mark
  835.     mov    dl,al        ;set arg 4 (last)
  836.     pop    ax        ;restore arg 3 (first)
  837.     mov    dh,al
  838.     pop    cx        ;restore arg 2 (end) pushed as ax.
  839.     pop    ax        ;restore arg 1 (start)
  840.     mov    ch,al
  841.     call    search
  842.     jc    lk_prim_1
  843.     jmp    return_null
  844. lk_prim_1:
  845.     mov    cx,5
  846.     jmp    return_arg_active
  847.  
  848.  
  849. ;find the first and next occurrences of a file.
  850. ff_prim:
  851.     mov    dx,offset filename2
  852.     mov    ah,1ah
  853.     int    21h
  854.     call    getarg1_filename
  855.     di_points_fend
  856.     mov    dx,si
  857.     mov    ah,4eh            ;find first matching file
  858.     mov    cx,0
  859. ff_prim_1:
  860.     int    21h            ;find first or find next.
  861.     jc    ff_prim_2
  862.     mov    si,offset filename2.find_buf_name
  863. ff_prim_3:
  864.     lodsb
  865.     or    al,al
  866.     je    ff_prim_4
  867.     chk_actptr
  868.     stosb
  869.     jmp    ff_prim_3
  870. ff_prim_4:
  871.     mov    cx,2            ;copy the separator argument.
  872.     call    getarg
  873.     chk_actptr_cnt
  874.     rep    movsb
  875.  
  876.     mov    ah,4fh            ;find next.
  877.     jmp    ff_prim_1
  878. ff_prim_2:
  879.     jmp    return_tos
  880.  
  881.  
  882. ;rename a file.
  883. rn_prim:
  884.     call    getarg1_filename
  885.     mov    cx,2
  886.     call    getarg
  887.     mov    di,offset filename2
  888.     rep    movsb
  889.     xor    al,al
  890.     stosb
  891.     mov    dx,offset filename
  892.     mov    di,offset filename2
  893.     mov    ah,56h            ;rename file
  894.     int    21h
  895.     jnc    rn_prim_1
  896.     mov    si,offset rename_error
  897.     mov    cx,rename_error_len
  898.     jmp    return_sicx
  899. rn_prim_1:
  900.     jmp    return_null
  901.  
  902.  
  903. ;delete a file.
  904. de_prim:
  905.     call    getarg1_filename
  906.     mov    dx,si
  907.     mov    ah,41h            ;delete file
  908.     int    21h
  909.     jnc    de_prim_1
  910.     mov    al,2
  911.     mov    bx,offset read_errors
  912.     jmp    return_string
  913. de_prim_1:
  914.     jmp    return_null
  915.  
  916.  
  917. ;read a file
  918. rf_prim:
  919.     call    getarg1_filename
  920.     call    read_file
  921.     mov    bx,offset read_errors
  922.     jmp    return_string
  923.  
  924.  
  925. ;write a file.
  926. wf_prim:
  927.     call    getarg1_filename
  928.     push    si            ;preserve the pointer to the filename.
  929.     mov    cx,2
  930.     call    getarg_mark
  931.     pop    si
  932.     call    write_file
  933.     mov    bx,offset write_errors
  934.     jmp    return_string
  935.  
  936.  
  937. ;allocate a buffer
  938. ba_prim:
  939.     call    getarg1
  940.     call    get_decimal
  941.     push    ax
  942.     mov    cx,2
  943.     call    getarg
  944.     mov    ax,cx
  945.     pop    cx            ;pushed as ax.
  946.     call    buffer_allocate
  947.     di_points_fbgn
  948.     jmp    return_number
  949.  
  950.  
  951. ;insert from a buffer
  952. ;#(bi,buffer number,mark,yes,no)
  953. bi_prim:
  954.     call    getarg1            ;get the buffer number.
  955.     call    get_decimal
  956.     push    ax
  957.     mov    cx,2            ;get the mark.
  958.     call    getarg_mark
  959.     pop    cx
  960.     call    buffer_insert
  961.     jc    bi_prim_1        ;go if we can't insert it.
  962.     mov    cx,3
  963.     jmp    return_arg
  964. bi_prim_1:
  965.     mov    cx,4
  966.     jmp    return_arg
  967.  
  968.  
  969. ao_prim:
  970.     call    getarg1        ;get the first argument
  971.     mov    dx,cx        ;save size of first argument
  972.     mov    di,si        ;save pointer to first argument
  973.     mov    cx,2        ;get second argument
  974.     call    getarg
  975.     cmp    cx,dx        ;second shorter than first?
  976.     jb    ao_prim_2    ;yes - use second's length.
  977.     mov    cx,dx        ;no - use first's length.
  978.     repe    cmpsb        ;strings alphabetically ordered?
  979.     jb    ao_prim_4    ;no, return 4th.
  980.     jmp    short ao_prim_3
  981. ao_prim_2:
  982.     repe    cmpsb        ;strings alphabetically ordered?
  983.     jbe    ao_prim_4    ;no, return 4th.
  984. ao_prim_3:
  985.     mov    cx,3
  986.     jmp    return_arg
  987. ao_prim_4:
  988.     mov    cx,4
  989.     jmp    return_arg
  990.  
  991.  
  992. it_prim:
  993. ;check for key, timed.
  994.     call    check_for_key        ;character waiting?
  995.     jne    it_prim_1        ;yes - don't turn the pick on.
  996.     call    pick_on
  997.     call    it_prim_1
  998.     call    pick_off
  999.     ret
  1000. it_prim_1:
  1001.     call    getarg1
  1002.     call    get_decimal
  1003.     mov    bp,ax            ;save the wait time.
  1004.     xor    si,si            ;si is the elapsed time.
  1005.     mov    ah,2ch            ;get the current hundreths.
  1006.     int    21h
  1007.     mov    bl,dl
  1008. it_prim_2:
  1009.     call    check_for_key        ;character waiting?
  1010.     jne    it_prim_3        ;yes - return it.
  1011.     call    check_pick        ;pick waiting?
  1012.     jne    ic_prim_2        ;yes - return it.
  1013.     mov    ah,2ch            ;gtime
  1014.     int    21h
  1015.     mov    al,dl            ;subtract the new time from the old.
  1016.     sub    al,bl
  1017.     mov    bl,dl            ;update the time in bl.
  1018.     cbw
  1019.     jns    it_prim_4        ;go if it's positive.
  1020.     add    ax,100            ;make it positive.
  1021. it_prim_4:
  1022.     add    si,ax            ;add in to the current time.
  1023.     cmp    si,bp            ;time to timeout yet?
  1024.     jb    it_prim_2        ;no.
  1025.     mov    ax,255            ;yes - timeout.
  1026.     jmp    short ic_prim_2
  1027. it_prim_3:
  1028.     or    bp,bp            ;original wait time.
  1029.     jz    ic_prim_2        ;if zero wait, we're just checking.
  1030.     call    get_key_value
  1031. ic_prim_2:
  1032.     cmp    ax,breakchar        ;is it the break char?
  1033.     je    ic_prim_1        ;yes - halt.
  1034.     call    decode_key        ;no - change the key into a string.
  1035.     di_points_fbgn
  1036.     chk_actptr_cnt
  1037.     rep    movsb
  1038.     jmp    return_tos
  1039. ic_prim_1:
  1040.     jmp    init_ids
  1041.  
  1042.  
  1043.     if    0
  1044. lc_prim:
  1045.     call    getarg1
  1046.     di_points_fbgn
  1047.     chk_actptr_cnt
  1048.     jcxz    lc_prim_1
  1049. lc_prim_2:
  1050.     lodsb
  1051.     cmp    al,'A'
  1052.     jb    lc_prim_3
  1053.     cmp    al,'Z'
  1054.     ja    lc_prim_3
  1055.     add    al,'a'-'A'
  1056. lc_prim_3:
  1057.     stosb
  1058.     loop    lc_prim_2
  1059. lc_prim_1:
  1060.     jmp    return_tos
  1061.  
  1062.     endif
  1063.  
  1064.  
  1065. bc_prim:
  1066.     mov    cx,2        ;get 'from' argument.
  1067.     call    getarg
  1068.     mov    dl,'a'        ;default to ASCII
  1069.     jcxz    bc_prim_1
  1070.     mov    dl,[si]        ;get from type.
  1071. bc_prim_1:
  1072.     mov    cx,3        ;get 'to' argument.
  1073.     call    getarg
  1074.     mov    dh,'d'        ;default to decimal
  1075.     jcxz    bc_prim_2
  1076.     mov    dh,[si]
  1077. bc_prim_2:
  1078.     call    getarg1
  1079.     call    bc_prim_base    ;get the source base.
  1080.     or    bx,bx        ;ASCII?
  1081.     jnz    bc_prim_4    ;no.
  1082.     jcxz    bc_prim_6
  1083.     lodsb
  1084.     mov    ah,0
  1085.     jmp    bc_prim_3
  1086. bc_prim_6:
  1087.     mov    ax,-1        ;if ASCII, and null argument, use -1.
  1088.     jmp    bc_prim_3
  1089. bc_prim_4:
  1090.     push    dx        ;preserve dx.
  1091.     call    get_number
  1092.     pop    dx
  1093. bc_prim_3:
  1094. ;we now have the number in ax.
  1095.     mov    dl,dh
  1096.     call    bc_prim_base
  1097.     di_points_fbgn
  1098.     or    bx,bx
  1099.     jnz    bc_prim_5
  1100.     stosb
  1101.     jmp    return_tos
  1102. bc_prim_5:
  1103.     mov    cx,0        ;use only as many digits as are needed.
  1104.     call    put_number
  1105.     jmp    return_tos
  1106.  
  1107.  
  1108. ;private subroutine, used only bc_prim.
  1109. bc_prim_base:
  1110. ;enter with dl=base character.
  1111. ;exit with bx=base if number; bx=0 if ASCII.
  1112.     or    dl,20h        ;convert UPPER case to lower case.
  1113.     cmp    dl,'d'
  1114.     jne    bc_prim_base_1
  1115.     mov    bx,10
  1116.     ret
  1117. bc_prim_base_1:
  1118.     cmp    dl,'o'
  1119.     jne    bc_prim_base_2
  1120.     mov    bx,8
  1121.     ret
  1122. bc_prim_base_2:
  1123.     cmp    dl,'h'
  1124.     jne    bc_prim_base_3
  1125.     mov    bx,16
  1126.     ret
  1127. bc_prim_base_3:
  1128.     cmp    dl,'c'
  1129.     jne    bc_prim_base_4
  1130.     mov    bx,0
  1131.     ret
  1132. bc_prim_base_4:
  1133.     cmp    dl,'a'        ;a alias character.
  1134.     jne    bc_prim_base_5
  1135.     mov    bx,0
  1136.     ret
  1137. bc_prim_base_5:
  1138.     cmp    dl,'b'
  1139.     jne    bc_prim_base_6
  1140.     mov    bx,2
  1141.     ret
  1142. bc_prim_base_6:
  1143.     ret
  1144.  
  1145.  
  1146. getarg_mark1:
  1147.     mov    cx,1
  1148. getarg_mark:
  1149. ;enter with cx=arg number.
  1150. ;exit with al=mark, cx=arg size, si->arg.
  1151.     call    getarg
  1152.     mov    al,0        ;use null if no string specified.
  1153.     jcxz    getarg_mark_1
  1154.     mov    al,[si]        ;get the first character
  1155. getarg_mark_1:
  1156.     ret
  1157.  
  1158.  
  1159.     public    trace_invoke
  1160. trace_invoke:
  1161.     public    trace_result
  1162. trace_result:
  1163.     ret
  1164.  
  1165. ex_prim:
  1166.     call    getarg1_filename
  1167.     push    si
  1168.     mov    cx,2
  1169.     call    getarg
  1170.     pop    di
  1171.     call    execute_program
  1172.     di_points_fbgn
  1173.     jmp    return_number
  1174.  
  1175. ef_prim:
  1176.     mov    cx,3
  1177.     call    getarg_mark
  1178.     push    ax
  1179.     call    getarg1_filename
  1180.     push    si
  1181.     mov    cx,2
  1182.     call    getarg
  1183.     pop    di
  1184.     pop    ax
  1185.     call    execute_filter
  1186.     di_points_fbgn
  1187.     jmp    return_number
  1188.  
  1189.     extrn    execute_program: near
  1190.     extrn    execute_filter: near
  1191.  
  1192.     extrn    get_key_value: near
  1193.     extrn    decode_key: near
  1194.     extrn    buffer_insert: near
  1195.  
  1196.     extrn    return_arg: near
  1197.     extrn    return_number: near
  1198.     extrn    return_null: near
  1199.     extrn    return_sicx: near
  1200.     extrn    return_tos: near
  1201.     extrn    return_arg_active: near
  1202.     extrn    return_string: near
  1203.     extrn    getarg1_filename: near
  1204.     extrn    getarg_filename: near
  1205.     extrn    getarg1: near
  1206.     extrn    getarg: near
  1207.     extrn    get_decimal: near
  1208.     extrn    get_number: near
  1209.     extrn    put_number: near
  1210.     extrn    find_arg1: near
  1211.  
  1212. ;the following externs are defined in mintprim.asm
  1213.     extrn    dflt: near
  1214.     extrn    hl_prim: near
  1215.     extrn    eq_prim: near
  1216.     extrn    nc_prim: near
  1217.     extrn    db_prim: near
  1218.     extrn    dt_prim: near
  1219.     extrn    tm_prim: near
  1220. ;forms
  1221.     extrn    ds_prim: near
  1222.     extrn    ss_prim: near
  1223.     extrn    cl_prim: near
  1224.     extrn    cc_prim: near
  1225.     extrn    cn_prim: near
  1226.     extrn    cr_prim: near
  1227.     extrn    in_prim: near
  1228.     extrn    ev_prim: near
  1229.     extrn    ln_prim: near
  1230.     extrn    dd_prim: near
  1231.     extrn    sb_prim: near
  1232.     extrn    fb_prim: near
  1233.     extrn    nb_prim: near
  1234. ;math
  1235.     extrn    ad_prim: near
  1236.     extrn    su_prim: near
  1237.     extrn    ml_prim: near
  1238.     extrn    dv_prim: near
  1239.     extrn    md_prim: near
  1240.     extrn    gr_prim: near
  1241.  
  1242.     public    ex_prim
  1243.     public    ef_prim
  1244.  
  1245.     public    sa_prim
  1246.     public    is_prim
  1247.     public    bc_prim
  1248.     public    sv_prim
  1249.     public    lv_prim
  1250.     public    pp_prim
  1251.     public    bl_prim
  1252.     public    sm_prim
  1253.     public    sp_prim
  1254.     public    dm_prim
  1255.     public    rm_prim
  1256.     public    rc_prim
  1257.     public    mb_prim
  1258.     public    lp_prim
  1259.     public    lr_prim
  1260.     public    lk_prim
  1261.     public    rf_prim
  1262.     public    wf_prim
  1263.     public    an_prim
  1264.     public    ow_prim
  1265.     public    xy_prim
  1266.     public    pm_prim
  1267.     public    ba_prim
  1268.     public    bi_prim
  1269.     public    ff_prim
  1270.     public    rn_prim
  1271.     public    de_prim
  1272.     public    st_prim
  1273.   if test_prims
  1274.     public    ts_prim
  1275.     public    tt_prim
  1276.   endif
  1277.  
  1278.  
  1279. code    ends
  1280.  
  1281. data    segment    byte public
  1282.     public    function_name_table
  1283.     public    function_name_length
  1284.     public    function_address
  1285.  
  1286. function_name_table    label    word
  1287.     db    'rd'
  1288.     db    'it'
  1289.  
  1290.     db    '=='            ;equals
  1291.     db    'nc'            ;number of characters
  1292.     db    'dt'            ;date
  1293.     db    'tm'            ;time
  1294.     db    'a?'            ;alphabetic ordered?
  1295.     db    'sa'            ;sort ascending
  1296. ;forms
  1297.     db    'ds'            ;define string
  1298.     db    'mp'            ;make parameter
  1299.     db    'gs'            ;get string
  1300.     db    'go'            ;get one
  1301.     db    'gn'            ;get n
  1302.     db    'rs'            ;reset string
  1303.     db    'fm'            ;first match
  1304.     db    'ev'            ;read enviornment
  1305.     db    'ls'            ;list strings
  1306.     db    'es'            ;erase string
  1307.     db    'sl'            ;save library
  1308.     db    'll'            ;load library
  1309.     db    'n?'            ;name exists?
  1310. ;math
  1311.     db    '++'            ;add
  1312.     db    '--'            ;subtract
  1313.     db    '**'            ;multiply
  1314.     db    '//'            ;divide
  1315.     db    '%%'            ;modulus
  1316.     db    'g?'            ;numeric greater
  1317.  
  1318.     db    'is'            ;insert string
  1319.     db    'bc'            ;base conversion
  1320.     db    'sv'            ;set variable
  1321.     db    'lv'            ;load variable
  1322.     db    'pp'            ;pick position
  1323.     db    'bl'            ;bell
  1324.     db    'sm'            ;set mark
  1325.     db    'sp'            ;set point
  1326.     db    'dm'            ;del to mark
  1327.     db    'rm'            ;read to mark
  1328.     db    'rc'            ;read to mark
  1329.     db    'mb'            ;mark before
  1330.     db    'lp'            ;look pattern
  1331.     db    'lr'            ;look regexp
  1332.     db    'lk'            ;look
  1333.     db    'rf'            ;read file
  1334.     db    'wf'            ;write file
  1335.     db    'an'            ;announce
  1336.     db    'ow'            ;overwrite
  1337.     db    'xy'            ;gotoxy
  1338.     db    'pm'            ;push/pop mark
  1339.     db    'ba'            ;buffer allocate
  1340.     db    'bi'            ;buffer insert
  1341.     db    'ff'            ;find files
  1342.     db    'rn'            ;rename file
  1343.     db    'de'            ;delete file
  1344.     db    'st'            ;syntax table
  1345.     db    'hl'            ;halt
  1346.     db    'db'            ;debug
  1347.     db    'ex'
  1348.     db    'ef'
  1349.   if test_prims
  1350.     db    'ts'
  1351.     db    'tt'
  1352.   endif
  1353.  
  1354. function_name_length    equ ($-function_name_table)/2
  1355.  
  1356.     dw    dflt
  1357. function_address    label    word
  1358.     dw    rd_prim        ;redisplay
  1359.     dw    it_prim        ;input timed.
  1360.     dw    eq_prim
  1361.     dw    nc_prim
  1362.     dw    dt_prim
  1363.     dw    tm_prim
  1364.     dw    ao_prim
  1365.     dw    sa_prim
  1366. ;forms
  1367.     dw    ds_prim
  1368.     dw    ss_prim
  1369.     dw    cl_prim
  1370.     dw    cc_prim
  1371.     dw    cn_prim
  1372.     dw    cr_prim
  1373.     dw    in_prim
  1374.     dw    ev_prim
  1375.     dw    ln_prim
  1376.     dw    dd_prim
  1377.     dw    sb_prim
  1378.     dw    fb_prim
  1379.     dw    nb_prim
  1380. ;math
  1381.     dw    ad_prim
  1382.     dw    su_prim
  1383.     dw    ml_prim
  1384.     dw    dv_prim
  1385.     dw    md_prim
  1386.     dw    gr_prim
  1387.  
  1388.     dw    is_prim        ;insert string
  1389.     dw    bc_prim        ;base convert
  1390.     dw    sv_prim        ;set variable
  1391.     dw    lv_prim        ;load variable
  1392.     dw    pp_prim        ;pick position
  1393.     dw    bl_prim        ;bell
  1394.     dw    sm_prim        ;set mark
  1395.     dw    sp_prim        ;set point
  1396.     dw    dm_prim        ;delete to mark
  1397.     dw    rm_prim        ;read to mark
  1398.     dw    rc_prim        ;count to mark
  1399.     dw    mb_prim        ;mark before
  1400.     dw    lp_prim        ;look pattern
  1401.     dw    lr_prim        ;look regexp
  1402.     dw    lk_prim        ;look
  1403.     dw    rf_prim        ;read file
  1404.     dw    wf_prim        ;write file
  1405.     dw    an_prim        ;announce
  1406.     dw    ow_prim        ;overwrite
  1407.     dw    xy_prim        ;gotoxy
  1408.     dw    pm_prim        ;push/pop mark
  1409.     dw    ba_prim        ;buffer allocate
  1410.     dw    bi_prim        ;buffer insert
  1411.     dw    ff_prim        ;find first/next
  1412.     dw    rn_prim        ;rename file
  1413.     dw    de_prim        ;delete file
  1414.     dw    st_prim        ;set the syntax table.
  1415.     dw    hl_prim
  1416.     dw    db_prim
  1417.     dw    ex_prim
  1418.     dw    ef_prim
  1419.   if test_prims
  1420.     dw    ts_prim        ;test
  1421.     dw    tt_prim        ;test two
  1422.   endif
  1423.  
  1424. data    ends
  1425.  
  1426.  
  1427.     end
  1428.